Mathematica in theory and practice

Start up: Excel, webserver

Initialize

<< Algebra`InequalitySolve`

<< Graphics`InequalityGraphics`

<< Statistics`DescriptiveStatistics`

<< Graphics`Animation`

Needs["GUIKit`"];

Block[{$Path = Join[$Path, $GUIPath]},
Get["EquationTrekker`EquationTrekker`"]];

SetOptions[ListDensityPlot,  Mesh -> False,  
      AspectRatio -> Automatic]

SeedRandom[1234]; 
    dna = StringJoin[
        Table[{"a", "c", "g", "t"}[[Random[
                Integer, {1, 4}]]], {1000}]];

ColorIt[s_String, color_] := 
      StyleBox[s, FontColor -> color, 
        FontWeight -> Bold]

ShowIt[data_] := 
      CellPrint[Cell[TextData @@ data, "Output"]]

What's there, what's new?

First audience to see Mathematica 5.1...

Mathematica 5: Speed. Scope. Scalability. 5.1: "data functions release".

Aim here: give you a taste of what Mathematica can do.

Solving equations

The largest range of solving with a very small number of functions.

Algebraic and calculus solving

Reduce[(x^2) - 2 (y^2) == 1, {x, y}]

Reduce[(x^2) - 2 (y^2) == 1, {x, y},  Reals]

Reduce[(x^2) - 2 (y^2) == 1, {x, y},  Integers]

∫(1/(1 - (x^5))) \[DifferentialD]x

Integrate[
      Boole[1/2 < Sin[x] < 2/3]/
        (x^2), {x, -∞, ∞}]

Assuming[x∈ℝ,∫\[LeftBracketingBar]2 - \[LeftBracketingBar]x\[RightBracketingBar]\[RightBracketingBar] \[DifferentialD]x]

DSolve and piecewise functions

DSolve[Max[t, (t^2)] y[t]+y'[t]==UnitStep[t]&&y[0] == 1,y[t],t]

NDSolve and the event handler

Analysing some data

FindFit

datatofit = 
        Import["C:\\Documents and Settings\\conrad\\My \
Documents\\Talks\\Data\\datatofit.dat"];

dataplot = ListPlot[datatofit]

FindFit[datatofit, a Exp[-(((x - μ))^2)/s], {a, μ, s},  
      x]

Plot[%, {x, -5, 5}, PlotRange -> All, 
        Epilog -> First[dataplot]];

Photo image analysis

photo = 
        Import["C:\\Documents and Settings\\conrad\\My Documents\\My \
Pictures\\Derivative for web, screen\\Grasshoper in Arizona.jpg"];

Show[photo]

datafromphoto = (photo  /.  
              Graphics[Raster[data_, __], __] -> data)  //  
          N;

monodatafromphoto  =  Map[Mean, datafromphoto, {2}];

ListDensityPlot[monodatafromphoto ]

edgedetected=ListConvolve[(({{1, 1, 1}, {1, -8, 1}, {1, 1, 1}})),monodatafromphoto];

ListDensityPlot[edgedetected]

Outputing your results

EquationTrekker[{ x''[t]  +  γ x'[ t]  -  
            x[t]  +  x[t]^3  ==  ϵ Cos[ω t]},  
      x,  {t, 0, 20}, 
      PlotRange -> {{-2, 2}, {-3, 
            3}}, 
TrekParameters -> {γ -> 
            Parameter[0.15],  ϵ -> 
            Parameter[0.3],  ω -> 
            Parameter[1,  {0, 2}]}]

Your own models

Expanding Logs

Expand logarithmic functions...

log[a_ b_] :=  log[a]  +  log[b]
\(log[a_\^n_] := \ n\ log[a]\)

Electric circuit

Impedence[Resistor[r_], ω_] :=  r
Impedence[Capacitor[c_], ω_] :=  
      (1/(I ω c))
Impedence[
        Inductor[
          l_], ω_] :=  I ω l

    
Impedence[InSeries[e_], ω_] :=  
      Apply[Plus,  
        Map[Impedence[#, ω] &, e]]
Impedence[InParallel[e_], ω_] :=  
      1/Apply[Plus,  1/Map[Impedence[#, ω] &, e]]

Impedence[
      InSeries[{InParallel[{Inductor[l], Capacitor[c],  Resistor[r]}], 
          InParallel[{Resistor[2  r],  
              Capacitor[2  c]}]}], ω]

Plot[
      Abs[%  /.  {l -> 1,  r -> 1,  c -> 1}],  {ω, 
        0, 10}]

Next prime number

Find the next prime number after the given integer.

NextPrime[n_Integer]:=
	Module[{k=n},
		While[!PrimeQ[k],k++];
		Return[k]
	]

Random Walks

Produce a random walk in one dimension...

FunctionalWalk[n_Integer?Positive]:=
	FoldList[Plus,0,
	Table[Random[Real,{-1,1}],{n}]]

Change to 2-dimensional example...

Matching patterns

An easy way to program

log[a_ b_] :=  log[a] +  log[b]
\(log[a_\^n_] := n\ log\ a\)

Now with strings...

This highlights subsequences of 4 bases, where the first base is "a" and the second and fourth base are identical. Let's first find cases where the third base is an "a".

StringReplace[dna, 
        p : ("a" ~~ x_ ~~ "a" ~~ x_) :> 
          ColorIt[p, Blue]] // ShowIt

Here, the third base is a "c".

StringReplace[dna, 
        p : ("a" ~~ x_ ~~ "c" ~~ x_) :> 
          ColorIt[p, Brown]] // ShowIt

Here, a "g".

StringReplace[dna, 
        p : ("a" ~~ x_ ~~ "g" ~~ x_) :> 
          ColorIt[p, Purple]] // ShowIt

Here, a "t"

StringReplace[dna, 
        p : ("a" ~~ x_ ~~ "t" ~~ x_) :> 
          ColorIt[p, Red]] // ShowIt

Here we look for all cases, regardless of what the third base is, and color it correspondingly (not worrying about possible overlapping subsequences).

StringReplace[dna, 
        p : ("a" ~~ x_ ~~ y_ ~~ x_) :> 
          ColorIt[p, 
            Switch[y, "a", Blue, "c", Brown, "g", 
              Purple, "t", Red, _, Yellow]]] // ShowIt

Interfacing with your results

Notebooks

Active content

One source, multiple media

Standards compatibility: XML, MathML, HTML etc.

Typeset paper

Alternatives

Built using the GUIkit...just released.

EquationTrekker[{ x''[t]  +  γ x'[ t]  -  
            x[t]  +  x[t]^3  ==  ϵ Cos[ω t]}, 
      x,  {t, 0, 20}, PlotRange -> {{-2, 2}, {-3, 3}}, 
      TrekParameters -> {γ -> 
            Parameter[0.15],  ϵ -> 
            Parameter[0.3],  ω -> 
            Parameter[1,  {0, 2}]}]

Giganumerics

How Mathematica 5 stacks up

Live example

<<  Optimization`MPSData`

\(\({cc, \ AA, \ bb, \ dd}\  = \ 
        ToLinearProgrammingData[\ 
          Import["Optimization/Data/80bau3b.mps", \ "MPSData"\ ]];\)\)

AA

xo  =  
      LinearProgramming[ cc,  AA,  bb,  dd,  
          Method -> "InteriorPoint"] // Timing

cc . xo

Automatic algorithm selection

Numerical differential equation occurs with just one, highly versatile "superfunction": NDSolve.

ODE

Plot[
      Evaluate[f[x] /.  
          NDSolve[{f''[x]  +  (x^2) f[x] ==  
                Sin[(x^3)], f'[0] == 1, f[0] == 1}, 
            f[x], {x, 0, 5}]], {x, 0, 5}]

DAE

Plot[
      Evaluate[{f[x], g[x]}  /.  
          NDSolve[{f''[x]  +  (x^2) g[x] ==  Sin[(x^3)], 
              g[x] + Sin[f[x]] == 2, f'[0] == 1, 
              f[0] == 1}, {f[x], g[x]}, {x, 0, 5}]], {x, 0, 
        5}]

PDE

L = 10;
sol=NDSolve[{(((∂^2) u(t, x, 
                          y))/(∂t ∂t))==(((∂^2) u(t, x, 
                            y))/(∂x ∂x))+(((∂^2) u(t, x, 
                            y))/(∂y ∂y))-sin(u(t, x, y)),u(0, x, 
                      y) == (E^(-((x^2) + (y^2)))),Derivative[1, 0, 0][u](0, x, y)==0,u(t, -L, y) == u(t, L, y),u(t, x, -L) == u(t, x, L)},u,{t, 0, L},{x, -L, L} , {y, -L, L} ];
MoviePlot3D[ 
        Evaluate[ u[t, x, y]  /.  First[sol]],  {x,  -L, 
          L},  {y, -L, L},  {t,  0,  10},  
        PlotRange  ->  {0,  1},  PlotPoints  ->  35]

Symbolics

Keeping accuracy and understanding as far as possible into calculation—now quite far.

History

Precomputer: mostly symbolic
Early computing: all numeric
Now: optimisation of the best of both worlds.

Assumptions example

Precision control

Every day serious mistakes occur because computers get the wrong numrical result.

Typical problem

Iterate 11x - 2 with initial x=0.2 eg. in Excel

\(\(\(precisiontest[x_] := 11\ x - 2\)\(
\)
    \)\)
NestList[precisiontest, 0.2`30, 30]

Earlier example

example

Plot[example  /.  a -> 1,  {x, -2, 2}]

example  /.  {a -> 1`50, 
        x -> -1.00000000000000000000001`50}

Precision[%]

N[example  /.  {a -> 1,  
          x ->  -100000000000000000000001/
              100000000000000000000000}, 50]

Precision[%]

Coming up

Interactive graphics

World's largest collection of algorithms

More intelligence!